from langchain_community.chat_models import ChatTongyi
from langchain_core.prompts.prompt import PromptTemplate
import os

os.environ["DASHSCOPE_API_KEY"] = "sk-9d8f1914800e497f8717144e860f99bc"
llm = ChatTongyi()

invalid_prompt = PromptTemplate(
    input_variables=["adjective"],
    template="Tell me a {adjective} joke about cat. 中文回复我"
)

# 定义一个函数来生成回答
def generate_joke(adjective):
    prompt = invalid_prompt.format(adjective=adjective)
    response = llm.invoke(prompt)
    print(response)
    return response


# 调用函数生成一个笑话
joke = generate_joke("funny")
print(joke)